﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
namespace weighing
{
    /// <summary>
    /// 称重配制
    /// </summary>
    public class WeighingConfig : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public static WeighingConfig Default
        {
            get
            {
                return new WeighingConfig
                {                   
                    Times = 2,
                    OutTimes = 2,
                    InNecessarySend = true,
                    InNecessaryReceive = true,
                    InBindingReceive = false,
                    InNecessarySendWeighing = true,
                    OutBindingSend = false,
                    OutNecessaryReceive = true,
                    OutNecessarySend = true,
                    Unit = Unit.Tone,
                    digits = 2,
                    InLockSendCompany = false,
                    InLockReceiveCompany = false,
                    InLockMaterial = false,

                    outLockSendCompany = false,
                    outLockReceiveCompany = false,
                    outLockMaterial = false,
                    //内外车
                    CarLimit = 0,
                    //必须派车
                    IsMustSendCar = false,
                    //必须排对
                    IsMustCarQueue = false,

                    //超运
                    TranceLimit = false,
                    TranceLimitTonner = 0,

                    //超发
                    SendLimit = false,
                    SendLimitTone = 0,

                    //装车审核
                    ValidateLoad = false,
                    //卸货审核
                    ValidateUnLoad = false,

                    InCheckCarNumber = false,
                    OutCheckCarNumber = false,
                    // 保存数据时需要停车规范，红外连接 infrared connected
                    InfraredConnected = false,

                    MaxSameLimitCars = 1,
                    CallInFactoryRate = 5,
                    CallWaitInFactoryTime = 5 * 60 * 1000,
                    WaitDeleteMaxTime = 30,
                    YardUseType = YardUserType.Share,
                    MultipleMachines = false,
                    //指定磅房过磅
                    SpecifiedScaleHouse = false,
                    InNecessaryCar = false,
                    OutNecessaryCar = false,

                    InIgnoreTraeWeighing = false,
                    OutIgnoreTraeWeighing = false,

                    InNotSameCompany = false,
                    OutNotSameCompany = false,

                    InNecessaryMaterial = false,
                    OutNecessaryMaterial = false,
                    SelectDataLength = 10,
                };
            }
        }

  


        #region unit

        private Unit unit = Unit.Tone;
        /// <summary>
        /// 入库单位
        /// </summary>
        public Unit Unit
        {
            get { return unit; }
            set
            {
                unit = value;
                OnChanged(nameof(Unit));
            }
        }
        private int digits = 2;
        /// <summary>
        /// 小数位数
        /// </summary>
        public int Digits
        {
            get { return digits; }
            set
            {
                digits = value;
                OnChanged(nameof(Digits));
            }
        }

        #endregion

        #region 计算机数量

        private bool _multipleMachines;
        /// <summary>
        /// 计算机数量，默认单机
        /// </summary>
        public bool MultipleMachines
        {
            get { return _multipleMachines; }
            set
            {
                _multipleMachines = value;
                OnChanged(nameof(MultipleMachines));
            }
        }

        #endregion

        #region 内外车

        private int _carLimit;
        /// <summary>
        /// 0 所有车辆 1 内部车辆
        /// </summary>
        public int CarLimit
        {
            get { return _carLimit; }
            set
            {
                _carLimit = value;
                OnChanged(nameof(CarLimit));
            }
        }

        #endregion

        #region 必须派车
        private bool _isMustSendCar;
        public bool IsMustSendCar
        {
            get { return _isMustSendCar; }
            set
            {
                _isMustSendCar = value;
                OnChanged(nameof(IsMustSendCar));
            }
        }
        #endregion

        #region 必须排对
        private bool _isMustCarQueue;
        public bool IsMustCarQueue
        {
            get { return _isMustCarQueue; }
            set
            {
                _isMustCarQueue = value;
                OnChanged(nameof(IsMustCarQueue));
            }
        }
        #endregion

        #region 超运 trnce limit 
        private bool tranceLimit;
        public bool TranceLimit
        {
            get { return tranceLimit; }
            set
            {
                tranceLimit = value;
                OnChanged(nameof(TranceLimit));
            }
        }
        private decimal? tranceLimitTonner;
        public decimal TranceLimitTonner
        {
            get { return tranceLimitTonner ?? 0; }
            set
            {
                tranceLimitTonner = value;
                OnChanged(nameof(TranceLimitTonner));
            }
        }
        #endregion

        #region 超发
        private bool sendLimit;
        public bool SendLimit
        {
            get { return sendLimit; }
            set
            {
                sendLimit = value;
                OnChanged(nameof(SendLimit));
            }
        }

        private decimal sendLimitTone;
        /// <summary>
        /// 余吨 超发限止吨位，需要根据合同，订单，历史发货量，计算 。
        /// </summary>
        public decimal SendLimitTone
        {
            get { return sendLimitTone; }
            set
            {
                sendLimitTone = value;
                OnChanged(nameof(SendLimitTone));
            }
        }
        #endregion

        #region 装车审核
        private bool _validateLoad;
        /// <summary>
        /// true 开启 装车 确认 ，false 关闭 装车 确认
        /// </summary>
        public bool ValidateLoad
        {
            get { return _validateLoad; }
            set { _validateLoad = value; OnChanged(nameof(ValidateLoad)); }
        }
        #endregion

        #region 卸货审核
        private bool _validateUnLoad;
        /// <summary>
        /// true 开启 卸货确认 ，false 关闭 卸货确认
        /// </summary>
        public bool ValidateUnLoad
        {
            get { return _validateUnLoad; }
            set { _validateUnLoad = value; OnChanged(nameof(ValidateUnLoad)); }
        }
        #endregion

        #region 检查车牌号
        private bool inCheckCarNumber;

        public bool InCheckCarNumber
        {
            get { return inCheckCarNumber; }
            set
            {
                inCheckCarNumber = value;
                OnChanged(nameof(InCheckCarNumber));
            }
        }

        private bool outCheckCarNumber;

        public bool OutCheckCarNumber
        {
            get { return outCheckCarNumber; }
            set
            {
                outCheckCarNumber = value;
                OnChanged(nameof(OutCheckCarNumber));
            }
        }
        #endregion
        private int _times;
        /// <summary>
        /// 入库过磅总次数 1次 或 2次 默认2
        /// </summary>
        public int Times
        {
            get { return _times; }
            set
            {
                _times = value;
                OnChanged(nameof(Times));
            }
        }

        private int _outTimes;
        /// <summary>
        /// 出库 过磅总次数 1次 或 2次 默认2
        /// </summary>
        public int OutTimes
        {
            get { return _outTimes; }
            set
            {
                _outTimes = value;
                OnChanged(nameof(OutTimes));
            }
        }

        private bool inNecessarySendWeighing;
        /// <summary>
        /// 入库 过磅 原发净重必须
        /// </summary>
        public bool InNecessarySendWeighing
        {
            get { return inNecessarySendWeighing; }
            set
            {
                inNecessarySendWeighing = value;
                OnChanged(nameof(InNecessarySendWeighing));
            }
        }

        private bool inBindingReceive;
        /// <summary>
        /// 入库 过磅 判定收货方为使用单位
        /// </summary>
        public bool InBindingReceive
        {
            get { return inBindingReceive; }
            set
            {
                inBindingReceive = value;
                OnChanged(nameof(InBindingReceive));
            }
        }

        private bool inNecessarySend;
        /// <summary>
        /// 入库 过磅 发货信息是必须的
        /// </summary>
        public bool InNecessarySend
        {
            get { return inNecessarySend; }
            set
            {
                inNecessarySend = value;
                OnChanged(nameof(InNecessarySend));
            }
        }

        private bool inNecessaryReceive;
        /// <summary>
        /// 入库 过磅 收货信息是必须的
        /// </summary>
        public bool InNecessaryReceive
        {
            get { return inNecessaryReceive; }
            set
            {
                inNecessaryReceive = value;
                OnChanged(nameof(InNecessaryReceive));
            }
        }


        private bool outNecessarySend;
        /// <summary>
        /// 出库 过磅 发货信息是必须的
        /// </summary>
        public bool OutNecessarySend
        {
            get { return outNecessarySend; }
            set
            {
                outNecessarySend = value;
                OnChanged(nameof(OutNecessarySend));
            }
        }


        private bool outNecessaryReceive;
        /// <summary>
        /// 出库 过磅 收货信息是必须的
        /// </summary>
        public bool OutNecessaryReceive
        {
            get { return outNecessaryReceive; }
            set
            {
                outNecessaryReceive = value;
                OnChanged(nameof(OutNecessaryReceive));
            }
        }

        private bool outBindingSend;
        /// <summary>
        /// 出库 过磅 判定发货方为使用单位
        /// </summary>
        public bool OutBindingSend
        {
            get { return outBindingSend; }
            set
            {
                outBindingSend = value;
                OnChanged(nameof(OutBindingSend));
            }
        }

        #region in lock

        private bool inLockSendCompany;
        /// <summary>
        /// 入库过磅 锁定发货信息
        /// </summary>
        public bool InLockSendCompany
        {
            get { return inLockSendCompany; }
            set
            {
                inLockSendCompany = value;
                OnChanged(nameof(InLockSendCompany));
            }
        }


        private bool inLockReceiveCompany;
        /// <summary>
        /// 入库过磅 锁定发货信息
        /// </summary>
        public bool InLockReceiveCompany
        {
            get { return inLockReceiveCompany; }
            set
            {
                inLockReceiveCompany = value;
                OnChanged(nameof(InLockReceiveCompany));
            }
        }
        private bool inLockMaterial;
        /// <summary>
        /// 入库过磅 锁定发货信息
        /// </summary>
        public bool InLockMaterial
        {
            get { return inLockMaterial; }
            set
            {
                inLockMaterial = value;
                OnChanged(nameof(InLockMaterial));
            }
        }
        #endregion

        #region out lock 

        private bool outLockSendCompany;
        /// <summary>
        /// 入库过磅 锁定发货信息
        /// </summary>
        public bool OutLockSendCompany
        {
            get { return outLockSendCompany; }
            set
            {
                outLockSendCompany = value;
                OnChanged(nameof(OutLockSendCompany));
            }
        }


        private bool outLockReceiveCompany;
        /// <summary>
        /// 入库过磅 锁定发货信息
        /// </summary>
        public bool OutLockReceiveCompany
        {
            get { return outLockReceiveCompany; }
            set
            {
                outLockReceiveCompany = value;
                OnChanged(nameof(OutLockReceiveCompany));
            }
        }
        private bool outLockMaterial;
        /// <summary>
        /// 入库过磅 锁定发货信息
        /// </summary>
        public bool OutLockMaterial
        {
            get { return outLockMaterial; }
            set
            {
                outLockMaterial = value;
                OnChanged(nameof(OutLockMaterial));
            }
        }
        #endregion

        #region 手动保存数据必须规范停车
        private bool _infraredConnected;
        /// <summary>
        /// 手动过磅 红外 infrared
        /// </summary>
        public bool InfraredConnected
        {
            get { return _infraredConnected; }
            set
            {
                _infraredConnected = value;
                OnChanged(nameof(InfraredConnected));
            }
        }
        #endregion

        #region 销售过磅核对装车净重与过磅净重磅差

        private bool _saleVerifyDiffWeigh;
        /// <summary>
        ///  销售过磅是否核对装车净重与过磅净重磅差
        /// </summary>
        public bool SaleVerifyDiffWeigh
        {
            get { return _saleVerifyDiffWeigh; }
            set
            {
                _saleVerifyDiffWeigh = value;
                OnChanged(nameof(SaleVerifyDiffWeigh));
            }
        }

        private decimal _saleDiffWeigh;
        /// <summary>
        /// 装车合理磅差
        /// </summary>
        public decimal SaleDiffWeigh
        {
            get { return _saleDiffWeigh; }
            set
            {
                _saleDiffWeigh = value;
                OnChanged(nameof(SaleDiffWeigh));
            }
        }

        #endregion

        #region 采购过磅核对原发净重与收货净重磅差
        private bool _buyVerifyDiffWeigh;
        public bool BuyVerifyDiffWeigh
        {
            get { return _buyVerifyDiffWeigh; }

            set
            {
                _buyVerifyDiffWeigh = value;
                OnChanged(nameof(BuyVerifyDiffWeigh));
            }
        }

        private decimal _buyDiffWeigh;
        /// <summary>
        /// 采购合理磅差
        /// </summary>
        public decimal BuyDiffWeigh
        {
            get { return _buyDiffWeigh; }
            set
            {
                _buyDiffWeigh = value;
                OnChanged(nameof(BuyDiffWeigh));
            }
        }
        #endregion

        #region 同时允许过磅车数
        private int _maxSameLimitCars;
        public int MaxSameLimitCars
        {
            get { return _maxSameLimitCars; }
            set
            {
                _maxSameLimitCars = value;
                OnChanged(nameof(MaxSameLimitCars));
            }
        }
        #endregion

        #region 排对 呼叫入场等待时间
        private int _callInFactorytime;

        /// <summary>
        /// 排对 呼叫入场等待时间 默认5分钟
        /// </summary>
        public int CallWaitInFactoryTime
        {
            get { return _callInFactorytime; }
            set
            {
                _callInFactorytime = value;
                OnChanged(nameof(CallWaitInFactoryTime));
            }
        }
        #endregion

        #region 频率
        private int _callInFactoryRate;
        /// <summary>
        /// 排对 呼叫入场 默认5s 一次
        /// </summary>
        public int CallInFactoryRate
        {
            get { return _callInFactoryRate; }
            set
            {
                _callInFactoryRate = value;
                OnChanged(nameof(CallInFactoryRate));
            }
        }
        #endregion

        #region 呼叫次数
        private int _callInFactoryMaxTimes;
        /// <summary>
        /// 排对 呼叫入场 默认5s 一次
        /// </summary>
        public int CallInFactoryMaxTimes
        {
            get { return _callInFactoryMaxTimes; }
            set
            {
                _callInFactoryMaxTimes = value;
                OnChanged(nameof(CallInFactoryMaxTimes));
            }
        }
        #endregion

        #region 清除数据最大等待时间
        private int _waitDeleteMaxTime;
        /// <summary>
        /// 清除数据最大等待时间(分钟)
        /// </summary>
        public int WaitDeleteMaxTime
        {
            get { return _waitDeleteMaxTime; }
            set
            {
                _waitDeleteMaxTime = value;
                OnChanged(nameof(WaitDeleteMaxTime));
            }
        }
        #endregion

        #region 收发货地址使用类型
        private YardUserType _yardUseType;
        /// <summary>
        /// 排对 呼叫入场 默认5s 一次
        /// </summary>
        public YardUserType YardUseType
        {
            get { return _yardUseType; }
            set
            {
                _yardUseType = value;
                OnChanged(nameof(YardUseType));
            }
        }
        #endregion

        #region in  Necessary Receive Yard
        private bool inNecessaryReceiveYard;
        /// <summary>
        /// 入库 过磅 收货信息是必须的
        /// </summary>
        public bool InNecessaryReceiveYard
        {
            get { return inNecessaryReceiveYard; }
            set
            {
                inNecessaryReceiveYard = value;
                OnChanged(nameof(InNecessaryReceiveYard));
            }
        }
        #endregion

        #region in  Necessary Send Yard
        private bool inNecessarySendYard;
        /// <summary>
        /// 入库 过磅 收货信息是必须的
        /// </summary>
        public bool InNecessarySendYard
        {
            get { return inNecessarySendYard; }
            set
            {
                inNecessarySendYard = value;
                OnChanged(nameof(InNecessarySendYard));
            }
        }
        #endregion

        #region out  Necessary Receive Yard
        private bool outNecessaryReceiveYard;
        /// <summary>
        /// 入库 过磅 收货信息是必须的
        /// </summary>
        public bool OutNecessaryReceiveYard
        {
            get { return outNecessaryReceiveYard; }
            set
            {
                outNecessaryReceiveYard = value;
                OnChanged(nameof(OutNecessaryReceiveYard));
            }
        }
        #endregion

        #region out Necessary Send Yard
        private bool outNecessarySendYard;
        /// <summary>
        /// 入库 过磅 收货信息是必须的
        /// </summary>
        public bool OutNecessarySendYard
        {
            get { return outNecessarySendYard; }
            set
            {
                outNecessarySendYard = value;
                OnChanged(nameof(OutNecessarySendYard));
            }
        }
        #endregion

        #region in  Necessary Trans company
        private bool inNecessaryTranceCompany;
        /// <summary>
        /// 入库 运输公司信息是必须的
        /// </summary>
        public bool InNecessaryTranceCompany
        {
            get { return inNecessaryTranceCompany; }
            set
            {
                inNecessaryTranceCompany = value;
                OnChanged(nameof(InNecessaryTranceCompany));
            }
        }
        #endregion

        #region out  Necessary Trans company
        private bool outNecessaryTranceCompany;
        /// <summary>
        /// 入库 运输公司信息是必须的
        /// </summary>
        public bool OutNecessaryTranceCompany
        {
            get { return outNecessaryTranceCompany; }
            set
            {
                outNecessaryTranceCompany = value;
                OnChanged(nameof(OutNecessaryTranceCompany));
            }
        }
        #endregion

        #region specified scale house
        private bool _specifiedScaleHouse;
        /// <summary>
        /// 指定磅房过磅
        /// </summary>
        public bool SpecifiedScaleHouse
        {
            get { return _specifiedScaleHouse; }
            set
            {
                _specifiedScaleHouse = value;
                OnChanged(nameof(SpecifiedScaleHouse));
            }
        }

        #endregion

        #region ignore trae weighit

        private bool _inIgnoreTraeWeighing;
        /// <summary>
        /// 指定磅房过磅
        /// </summary>
        public bool InIgnoreTraeWeighing
        {
            get { return _inIgnoreTraeWeighing; }
            set
            {
                _inIgnoreTraeWeighing = value;
                OnChanged(nameof(InIgnoreTraeWeighing));
            }
        }

        private bool _outIgnoreTraeWeighing;
        public bool OutIgnoreTraeWeighing
        {
            get { return _outIgnoreTraeWeighing; }
            set
            {
                _outIgnoreTraeWeighing = value;
                OnChanged(nameof(OutIgnoreTraeWeighing));
            }
        }
        #endregion

        #region in  Necessary car
        private bool _inNecessaryCar;
        /// <summary>
        /// 入库车辆信息是必须的
        /// </summary>
        public bool InNecessaryCar
        {
            get { return _inNecessaryCar; }
            set
            {
                _inNecessaryCar = value;
                OnChanged(nameof(InNecessaryCar));
            }
        }
        #endregion

        #region out  Necessary car
        private bool _outNecessaryCar;
        /// <summary>
        /// 出库 车辆信息是必须的
        /// </summary>
        public bool OutNecessaryCar
        {
            get { return _outNecessaryCar; }
            set
            {
                _outNecessaryCar = value;
                OnChanged(nameof(OutNecessaryCar));
            }
        }
        #endregion


        #region in  Not Same Company
        private bool _inNotSameCompany;
        /// <summary>
        ///  收发公司不能相同
        /// </summary>
        public bool InNotSameCompany
        {
            get { return _inNotSameCompany; }
            set
            {
                _inNotSameCompany = value;
                OnChanged(nameof(InNotSameCompany));
            }
        }
        #endregion

        #region out  Not Same Company
        private bool _outNotSameCompany;
        /// <summary>
        /// 出库 收发公司不能相同
        /// </summary>
        public bool OutNotSameCompany
        {
            get { return _outNotSameCompany; }
            set
            {
                _outNotSameCompany = value;
                OnChanged(nameof(OutNotSameCompany));
            }
        }
        #endregion


        #region in  Necessary material
        private bool _inNecessaryMaterial;
        /// <summary>
        /// 出库 收发公司不能相同
        /// </summary>
        public bool InNecessaryMaterial
        {
            get { return _inNecessaryMaterial; }
            set
            {
                _inNecessaryMaterial = value;
                OnChanged(nameof(InNecessaryMaterial));
            }
        }
        #endregion

        #region out  Necessary material
        private bool _outNecessaryMaterial;
        /// <summary>
        /// 出库 收发公司不能相同
        /// </summary>
        public bool OutNecessaryMaterial
        {
            get { return _outNecessaryMaterial; }
            set
            {
                _outNecessaryMaterial = value;
                OnChanged(nameof(OutNecessaryMaterial));
            }
        }
        #endregion

        #region max drop down length 备选数据的长度

        private int _selectDataLength;

        public int SelectDataLength
        {
            get { return _selectDataLength; }
            set
            {
                _selectDataLength = value;
                OnChanged(nameof(SelectDataLength));
            }
        }
        #endregion

        #region weighing mode
        private WeighingMode _weighingMode;

        public WeighingMode WeighingMode
        {
            get { return _weighingMode; }
            set
            {
                _weighingMode = value;
                OnChanged(nameof(WeighingMode));
            }
        }
        #endregion


        /// <summary>
        /// 最小有效的吨位数量（单位吨）
        /// </summary>
        public decimal MixedValidTone { get; set; } = new decimal(0.1);

        public void OnChanged(String propertyName)
        {
            if (!propertyName.IsNullOrEmpty())
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
